package com.qst.service;

import com.qst.dao.IEmployeeDao;
import com.qst.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Eumenides.
 * @create 2021-06-17 10:50
 */
@Service
public class LoginService {
    @Autowired
    private IEmployeeDao employeeDao;

    public List<Employee> findAll() {
        return employeeDao.findAll();
    }

    public Employee findEmployeeByName(String username) {
        return employeeDao.findEmployeeByName(username);
    }

    public Employee login(String username, String password) {
        //在数据库通过用户名搜索一名用户
        Employee employee = employeeDao.findEmployeeByName(username);
        // 判断用户是否存在, 判读用户的密码是否填写正确
        if (employee == null || !employee.getPassword().equals(password)) {
            return null;
        }
        return employee;
    }

}
